jQuery.extend({

    /*
     *
     * constant variable
     *
     */

    constant: {

        page: {
            HOME: 1,
            USER: 2,
            PRODUCT: 3,
            QUOTA: 4,
            CUSTOMER: 5,
            SUBSCRIPTION: 6,
            BRANCH: 7,
            REPORT: 8,
            ALERT: 9,
            ABOUT: 10,
            CONTACTUS: 11
        }

    },

    /*
     *
     * cache variable
     *
     */

    cache: {},

    /*
     *
     * behavior function
     *
     */

    window: {
        go: function(link) {
            window.location = link;
        },

        popup: function(link) {
            window.open(link, 'KBOND', 'height=600, width=800, left=100, top=100, location=0, menubar=1, status=0, toolbar=0');
        }
    },

    /*
     *
     * ui function
     *
     */

    kui: {

        dialog: {

            alert: function(message, title) {
                $('body').append('<div id="alertdialog" title="' + title + '">' + message + '</div>');
                $('#alertdialog').dialog({
                    modal: true,
                    resizable: false,
                    minWidth: 350,
                    minHeight: 150,
                    buttons: [
                    {
                        text: 'Ok',
                        click: function() {
                            $(this).dialog("close");
                        }
                    }
                    ],
                    close: function() {
                        $(this).dialog("destroy");
                        $(this).remove();
                    }
                });
            },
            //confirm with out function hide & show select box
            confirmBox: function(message, title, oktext, okevent, canceltext, cancelevent) {
                $('body').append('<div id="confirmdialog" title="' + title + '">' + message + '</div>');            
                $('#confirmdialog').dialog({
                    modal: true,
                    resizable: false,
                    minWidth: 350,
                    minHeight: 150,
                    buttons: [
                    {
                        text: oktext,
                        click: function() {
                            $(this).dialog("close");
                            okevent();
                        }
                    },
                    {
                        text: canceltext == undefined ? 'Cancel' : canceltext,
                        click: cancelevent == undefined ? function() {
                            $(this).dialog("close");
                        } : function() {
                            $(this).dialog("close");
                            cancelevent();
                        }
                    }
                    ],
                    close: function() {                      	
                        $(this).dialog("destroy");
                        $(this).remove();
                    }           
                });
            },
            confirm: function(message, title, oktext, okevent, canceltext, cancelevent) {
                $('body').append('<div id="confirmdialog" title="' + title + '">' + message + '</div>');
                $('select').hide();
                $('#confirmdialog').dialog({
                    modal: true,
                    resizable: false,
                    minWidth: 350,
                    minHeight: 150,
//                    open: function(event, ui) {
//                        $(":button:contains('Cancel')").focus(); // Set focus to the [Ok] button
//                    },
                    buttons: [
                    {
                        text: oktext,
                        click: function() {
                            $(this).dialog("close");
                            okevent();
                        }
                    },
                    {
                        text: canceltext == undefined ? 'Cancel' : canceltext,
                        click: cancelevent == undefined ? function() {
                            $(this).dialog("close");
                        } : function() {
                            $(this).dialog("close");
                            cancelevent();
                        }
                    }
                    ],
                    close: function() {
                    	$('select').show();
                    	
                    	/*-------- Hidden --------*/
                    	$('#branchCode').hide();
                    	$('#productId').hide();
                    	$('#productNameListId').hide();
                    	
                    	/*------------------------*/
                    	
                        $(this).dialog("destroy");
                        $(this).remove();
                    }
                });
            },

            prompt: function(message, title, oktext, okevent) {
                //$('body').append('<div id="promptdialog" title="' + title + '"><div class="label" style="padding-left: 0px;">' + message + '</div><div><input type="text" id="promptvalue" value="" style="width: 300px;" /></div></div>');
                $('body').append('<div id="promptdialog" title="' + title + '">'+
                		'<table style="width: 100%;">'+
                		'<tr><td class="label">' + message + '</td><td><input type="text" id="promptvalue" class="input-width" value=""/></td></tr></table>'+		
                		'</div>');
                $('#promptdialog').dialog({
                    modal: true,
                    resizable: false,
                    minWidth: 330,
                    minHeight: 150,
                    buttons: [
                    {
                        text: oktext,
                        click: function() {
                            var value = $('#promptvalue').val();
                            $(this).dialog("close");
                            okevent(value);
                        }
                    },
                    {
                        text: 'Cancel',
                        click: function() {
                            $(this).dialog("close");
                        }
                    }
                    ],
                    close: function() {
                        $(this).dialog("destroy");
                        $(this).remove();
                    }
                });
            },
            
            prompt2: function(message, message2, title, oktext, okevent) {
                $('body').append('<div id="promptdialog" title="' + title + '">'+
                		'<table style="width: 100%;">'+
                		'<tr><td class="label">' + message + '</td><td><input type="text" id="promptvalue1" class="input-width" value=""/></td></tr>'+
                		'<tr><td class="label">' + message2 + '</td><td><input type="text" id="promptvalue2" class="input-width" value=""/></td></tr></table>'+		
                		'</div>');
                $('#promptdialog').dialog({
                    modal: true,
                    resizable: false,
                    minWidth: 330,
                    minHeight: 150,
                    buttons: [
					{
					    text: oktext,
					    click: function() {
					        var value1 = $('#promptvalue1').val();
					        var value2 = $('#promptvalue2').val();
					        $(this).dialog("close");
					        okevent(value1, value2);
					    }
					},          
                    {
                        text: 'Cancel',
                        click: function() {
                            $(this).dialog("close");
                        }
                    }
                    ],
                    close: function() {
                        $(this).dialog("destroy");
                        $(this).remove();
                    }
                });
            },
            
            prompt3: function(message, title, fieldSize, oktext, okevent) {
                
                $('body').append('<div id="promptdialog" title="' + title + '">'+
                		'<table style="width: 100%;">'+
                		'<tr><td class="label">' + message + '</td><td><input type="text" id="promptvalue" maxlength="'+fieldSize+'" class="input-width" value=""/></td></tr></table>'+		
                		'</div>');
                $('#promptdialog').dialog({
                    modal: true,
                    resizable: false,
                    minWidth: 330,
                    minHeight: 150,
                    buttons: [
                    {
                        text: oktext,
                        click: function() {
                            var value = $('#promptvalue').val();
                            $(this).dialog("close");
                            okevent(value);
                        }
                    },
                    {
                        text: 'Cancel',
                        click: function() {
                            $(this).dialog("close");
                        }
                    }
                    ],
                    close: function() {
                        $(this).dialog("destroy");
                        $(this).remove();
                    }
                });
            }

        },
    
        widget: {

            notice: function(message) {
                if($('#notice').length == 0) {
                    $('body').append('<div id="notice" class="widget-notice widget-notice-notice">' + message + '</div>');
                    $('#notice').slideDown('fast');
                    $.cache.widgetnotice = setTimeout(function(){
                        $('#notice').slideUp('fast', function(){
                            $('#notice').remove();
                            $.cache.widgetnotice = undefined;
                        });
                    }, 10000);
                } else {
                    $('#notice').html(message);
                    clearTimeout($.cache.widgetnotice);
                    $.cache.widgetnotice = setTimeout(function(){
                        $('#notice').slideUp('fast', function(){
                            $('#notice').remove();
                            $.cache.widgetnotice = undefined;
                        });
                    }, 10000);
                }
            },

            warning: function(message) {
                if($('#warning').length == 0) {
                    $('body').append('<div id="warning" class="widget-notice widget-notice-warning">' + message + '</div>');
                    $('#warning').slideDown('fast');
                    $.cache.widgetwarning = setTimeout(function(){
                        $('#warning').slideUp('fast', function(){
                            $('#warning').remove();
                            $.cache.widgetwarning = undefined;
                        });
                    }, 10000);
                } else {
                    $('#warning').html(message);
                    clearTimeout($.cache.widgetwarning);
                    $.cache.widgetwarning = setTimeout(function(){
                        $('#warning').slideUp('fast', function(){
                            $('#warning').remove();
                            $.cache.widgetwarning = undefined;
                        });
                    }, 10000);
                }
            }

        }

    },

    /*
     *
     * custom function
     *
     */

    postJSON: function(url, data, callback) {
        $.post(
            url,
            data,
            function(raw){
                var json = eval('('+raw+')');
                callback(json);
            },
            'text');
    }
});

function ajaxSubmitFormSimple(divObj,url, dataStr, block) {
	//alert('ajaxSubmitFormSimple');
	if(!block) {
		$.blockUI({ message: "<h1>Remote call in progress...</h1>" },divObj);
	} 
	/*alert(divObj+','+url+','+dataStr);*/
    $.post(url, dataStr, function(data){
    	//alert(data);
    	/*alert(divObj);*/
    	if(data.indexOf("#INVALID") > -1){//if return this case still show old data and its page
    		/*alert(data);*/
   			$('#errorResultDiv').show();
            $('#errorResultDiv').html(data);
        }else if(data.indexOf("#LOGIN") > -1){//if return this case still go to Login.jsp
        	/*alert('Redirect Login');*/
        	if(!block) {
            	$.unblockUI(divObj);
            } 
   			window.location="../login/Login_init.action";
   			return;
        }else {
        	/*alert('Else');*/
        	$('#errorResultDiv').html("");
        	
        	divObj.html(data);
        }
    	if(!block) {
        	$.unblockUI(divObj);
        } 
    }).error(function(xhr, status, error) {
        // Display a generic error for now.
    	alert(error);
    	if(!block) {
        	$.unblockUI(divObj);
        } 
    	$.kui.dialog.alert('Server not reponse.', 'Warning');
    });
    //alert(1);
	window.scrollTo(0,0);
}

function ajaxSubmitFormPaging(parameter,divObj,url, block) {
	//alert('ajaxSubmitFormPaging');
	
	/**
	 * Clear Display Error message
	 */
	$('#errorResultDiv').hide();
    $('#errorResultDiv').html("");
    
	if(!block) {
		$.blockUI({ message: "<h1>Remote call in progress...</h1>" },divObj);
	} 
	/*alert(divObj+','+url+','+dataStr);*/
    $.post(url+parameter, null, function(data){
    	/*alert(data);*/
    	/*alert(divObj);*/
    	if(data.indexOf("#INVALID") > -1){//if return this case still show old data and its page
   			$('#errorResultDiv').show();
            $('#errorResultDiv').html(data);
        }else if(data.indexOf("#LOGIN") > -1){//if return this case still go to Login.jsp
        	if(!block) {
            	$.unblockUI(divObj);
            } 
   			window.location="../login/Login_init.action";
        }else {
        	$('#errorResultDiv').html("");
        	
        	divObj.html(data);
        }
    	if(!block) {
        	$.unblockUI(divObj);
        } 
    }).error(function(xhr, status, error) {
        // Display a generic error for now.
    	if(!block) {
        	$.unblockUI(divObj);
        } 
    	$.kui.dialog.alert('Server not reponse.', 'Warning');
    });
    //alert(1);
	//window.scrollTo(0,0);
}

function ajaxUploadFile(divObjLoading,divObjBtnUpload,divObjList,divObjForm,url, block) {
	 
	if(!block) {
		divObjLoading.html("");
		divObjLoading.html("<img alt='' src='../images/loading42.gif' border='0'>");
		divObjBtnUpload.hide();
	} 
	
	divObjForm.ajaxSubmit({
		url: url,
		type: "post",
		cache: false,
		contentType: false,
		dataType: false,
	    processData: false,
		success: function(data,dataType,state) {
			//alert(data);
			if(data.indexOf("#INVALID") > -1){//if return this case still show old data and its page
				$('#errorResultDiv').show();
	            $('#errorResultDiv').html(data);
	        }else if(data.indexOf("#LOGIN") > -1){//if return this case still go to Login.jsp
	   			window.location="../login/Login_init.action";
	        }else {
	        	$('#errorResultDiv').html("");
	        	
	        	divObjList.html(data);
	        	divObjForm.each(function(){
	    	        this.reset();
	        	});
	        }
			
			if(!block) {
				divObjLoading.hide();
				divObjBtnUpload.show();
			} 
		}
	}).error(function(XMLHttpRequest, dataStatus, errorThrown) { 
		if(!block) {
			divObjLoading.hide();
			divObjBtnUpload.show();
		} 
		alert(errorThrown);
    	$.kui.dialog.alert('Server not reponse.', 'Warning');
    });

}

function ajaxJSonDropdown(urlServer, parameter,divSetDropdown) {
//	alert(urlServer);alert(parameter);
	var oXHR = $.ajax({
   		url: urlServer,
   		data: parameter,
   		dataType :'json',
   		success: function(data) {
//			alert('resultJSon = '+data);
	    	$.each(data.dropdownBeanList, function(i, item) {
	    		
	    		/*$("#"+divSetDropdown+" option").each(function(i) {
	    			if (i != 0) {
	    				$(this).remove();
	    			}
	    		});*/
	    		
	    		$("#"+divSetDropdown).append('<option value="'+item.valueCode+'">' + item.textName + '</option>'); 
//	    		alert('amphurId='+item.valueCode);alert('amphurName='+item.textName);
//	    		$("#"+divSetDropdown).append($("&lt;option/&gt;").attr("value", item.amphurId).text(item.amphurName)); 

			});
		},
		error : function(xhr, state, exception) {
			alert(exception);
			return null;
		}
	});
	    
}

function clearDropdown(divClearDropdown) {
	$("#"+divClearDropdown+" option").each(function(i) {
		if (i != 0) {
			$(this).remove();
		}
	});
}

function loadAmphur() {
	clearDropdown("amphurId");
	clearDropdown("districtId");
	var provinceId = $('#provinceId').val();
	ajaxJSonDropdown("EmployeeJson_findAmphur.action","provinceId="+provinceId,"amphurId");
}

function loadDistrict() {
	clearDropdown("districtId");
	var provinceId = $('#provinceId').val();
	var amphurId = $('#amphurId').val();
	ajaxJSonDropdown("EmployeeJson_findDistrict.action","provinceId="+provinceId+"&amphurId="+amphurId,"districtId");
}

function loadBrandSub() {
	clearDropdown("autobrandsubNo");
	var autobrandNo = $('#autobrandNo').val();
	ajaxJSonDropdown("CommonJson_findBrandSub.action","autobrandNo="+autobrandNo,"autobrandsubNo");
}

function isValidationField(formName) {
	//jQuery('#MMeter1').validationEngine('validate');
	jQuery('#'+formName+'').validationEngine();
	var $inputs = $('#'+formName+' :input');

    // not sure if you wanted this, but I thought I'd add it.
    // get an associative array of just the values.
    var values = {};
    var result = false;
    var index = 0;
    $inputs.each(function() {
    	var className = $(this).attr('class');
    	//alert('className = '+className);
    	if(typeof(className) != "undefined" && className.indexOf('validate[') > -1) {
    		var idName = $(this).attr('id');
    		//alert('idName = '+idName);
    		if(jQuery('#'+idName+'').validationEngine('validate')) {
    			result = true;
    			if(index == 0){
    				//alert(idName);
    				//alert(idName+'formErrorContent');
    				//alert($('#'+idName+'formErrorContent'+''));
    				//$('#'+idName+'formErrorContent'+'').focus();
    				$(window).scrollTop($('#'+idName+'formErrorContent'+'').offset().top);

    			}
    			index = index+1;
    		}
    	}
    	
    });
    return !result;
}

function moveNextFocus(next_id,_key) {
	//alert(next_id);
	var indexName = next_id.substring(0,next_id.lastIndexOf("_")+1);
	//alert('indexName='+indexName);
	var indexKey = parseInt(next_id.substring(next_id.lastIndexOf("_")+1,next_id.length))
	//alert('indexKey='+indexKey);
	var next_ctrl = indexName + (indexKey+1);
	//alert('next_ctrl='+next_ctrl);
        if (_key == 13) {
            var _next = document.getElementById(next_ctrl);
            _next.focus();
            return false;
        }
}

function loadProvice(divProvince,provinceName) {
	var parameter = '';
	
	if($('#zone1').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone1').val())+"&";
	}
	if($('#zone2').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone2').val())+"&";
	}
	if($('#zone3').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone3').val())+"&";
	}
	if($('#zone4').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone4').val())+"&";
	}
	if($('#zone5').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone5').val())+"&";
	}
	if($('#zone6').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone6').val())+"&";
	}
	
	//alert('parameter = '+parameter);
	$('#divProvince').html('');
	$('#divUniversity').html('');
	$('#divFaculty').html('');
	$('#divMajor').html('');
	
	ajaxJSonCheckBox("JsonCommonServlet",'mode=province&'+parameter,divProvince,provinceName, "loadUniversity('divUniversity','universityName')");
}

function loadUniversity(divUniversity,universityName) {
	
	var parameter1 = '';
	var parameter2 = '';
	
	$("#divZone :checked").each(function() {
		parameter1 = parameter1 + "zoneSelect="+toUnicode(this.value)+"&";
	});
	$("#divProvince :checked").each(function() {
		parameter2 = parameter2 + "provinceSelect="+toUnicode(this.value)+"&";
	});

	$('#divUniversity').html('');
	$('#divFaculty').html('');
	$('#divMajor').html('');
	ajaxJSonCheckBox("JsonCommonServlet",'mode=university&'+parameter1+parameter2,divUniversity,universityName, "loadFaculty('divFaculty','facultyName')");
}

function loadFaculty(divFaculty,facultyName) {
	
	var parameter1 = '';
	var parameter2 = '';
	var parameter3 = '';
	
	$("#divZone :checked").each(function() {
		parameter1 = parameter1 + "zoneSelect="+toUnicode(this.value)+"&";
	});
	$("#divProvince :checked").each(function() {
		parameter2 = parameter2 + "provinceSelect="+toUnicode(this.value)+"&";
	});
	$("#divUniversity :checked").each(function() {
		parameter3 = parameter3 + "universitySelect="+toUnicode(this.value)+"&";
	});

	$('#divFaculty').html('');
	$('#divMajor').html('');
	ajaxJSonCheckBox("JsonCommonServlet",'mode=faculty&'+parameter1+parameter2+parameter3,divFaculty,facultyName, "loadMajor('divMajor','majorName')");
}

function loadMajor(divMajor,majorName) {
	
	var parameter1 = '';
	var parameter2 = '';
	var parameter3 = '';
	var parameter4 = '';
	
	$("#divZone :checked").each(function() {
		parameter1 = parameter1 + "zoneSelect="+toUnicode(this.value)+"&";
	});
	$("#divProvince :checked").each(function() {
		parameter2 = parameter2 + "provinceSelect="+toUnicode(this.value)+"&";
	});
	$("#divUniversity :checked").each(function() {
		parameter3 = parameter3 + "universitySelect="+toUnicode(this.value)+"&";
	});
	$("#divFaculty :checked").each(function() {
		parameter4 = parameter4 + "facultySelect="+toUnicode(this.value)+"&";
	});

	$('#divMajor').html('');
	ajaxJSonCheckBox("JsonCommonServlet",'mode=major&'+parameter1+parameter2+parameter3+parameter4,divMajor,majorName, "");
}

////////////////////////////////////////

function loadProvice2(divProvince,provinceName) {
	var parameter = '';
	
	if($('#zone1').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone1').val())+"&";
	}
	if($('#zone2').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone2').val())+"&";
	}
	if($('#zone3').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone3').val())+"&";
	}
	if($('#zone4').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone4').val())+"&";
	}
	if($('#zone5').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone5').val())+"&";
	}
	if($('#zone6').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone6').val())+"&";
	}
	
	//alert('parameter = '+parameter);
	$('#divProvince').html('');
	$('#divUniversity').html('');
	$('#divFaculty').html('');
	$('#divMajor').html('');
	
	ajaxJSonCheckBox("JsonCommonServlet2",'mode=province&'+parameter,divProvince,provinceName, "loadUniversity2('divUniversity','universityName')");
}

function loadUniversity2(divUniversity,universityName) {
	
	var parameter1 = '';
	var parameter2 = '';
	
	$("#divZone :checked").each(function() {
		parameter1 = parameter1 + "zoneSelect="+toUnicode(this.value)+"&";
	});
	$("#divProvince :checked").each(function() {
		parameter2 = parameter2 + "provinceSelect="+toUnicode(this.value)+"&";
	});

	$('#divUniversity').html('');
	$('#divFaculty').html('');
	$('#divMajor').html('');
	ajaxJSonCheckBox("JsonCommonServlet2",'mode=university&'+parameter1+parameter2,divUniversity,universityName, "loadFaculty2('divFaculty','facultyName')");
}

function loadFaculty2(divFaculty,facultyName) {
	
	var parameter1 = '';
	var parameter2 = '';
	var parameter3 = '';
	
	$("#divZone :checked").each(function() {
		parameter1 = parameter1 + "zoneSelect="+toUnicode(this.value)+"&";
	});
	$("#divProvince :checked").each(function() {
		parameter2 = parameter2 + "provinceSelect="+toUnicode(this.value)+"&";
	});
	$("#divUniversity :checked").each(function() {
		parameter3 = parameter3 + "universitySelect="+toUnicode(this.value)+"&";
	});

	$('#divFaculty').html('');
	$('#divMajor').html('');
	ajaxJSonCheckBox("JsonCommonServlet2",'mode=faculty&'+parameter1+parameter2+parameter3,divFaculty,facultyName, "loadMajor2('divMajor','majorName')");
}

function loadMajor2(divMajor,majorName) {
	
	var parameter1 = '';
	var parameter2 = '';
	var parameter3 = '';
	var parameter4 = '';
	
	$("#divZone :checked").each(function() {
		parameter1 = parameter1 + "zoneSelect="+toUnicode(this.value)+"&";
	});
	$("#divProvince :checked").each(function() {
		parameter2 = parameter2 + "provinceSelect="+toUnicode(this.value)+"&";
	});
	$("#divUniversity :checked").each(function() {
		parameter3 = parameter3 + "universitySelect="+toUnicode(this.value)+"&";
	});
	$("#divFaculty :checked").each(function() {
		parameter4 = parameter4 + "facultySelect="+toUnicode(this.value)+"&";
	});

	$('#divMajor').html('');
	ajaxJSonCheckBox("JsonCommonServlet2",'mode=major&'+parameter1+parameter2+parameter3+parameter4,divMajor,majorName, "");
}

//////////////////////////////////////

function loadProvice3(divProvince,provinceName) {
	var parameter = '';
	
	if($('#zone1').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone1').val())+"&";
	}
	if($('#zone2').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone2').val())+"&";
	}
	if($('#zone3').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone3').val())+"&";
	}
	if($('#zone4').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone4').val())+"&";
	}
	if($('#zone5').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone5').val())+"&";
	}
	if($('#zone6').attr('checked')) {
		parameter = parameter + "zoneSelect="+toUnicode($('#zone6').val())+"&";
	}
	
	//alert('parameter = '+parameter);
	$('#divProvince').html('');
	$('#divUniversity').html('');
	$('#divFaculty').html('');
	$('#divMajor').html('');
	
	ajaxJSonCheckBox("JsonCommonServlet3",'mode=province&'+parameter,divProvince,provinceName, "loadUniversity3('divUniversity','universityName')");
}

function loadUniversity3(divUniversity,universityName) {
	
	var parameter1 = '';
	var parameter2 = '';
	
	$("#divZone :checked").each(function() {
		parameter1 = parameter1 + "zoneSelect="+toUnicode(this.value)+"&";
	});
	$("#divProvince :checked").each(function() {
		parameter2 = parameter2 + "provinceSelect="+toUnicode(this.value)+"&";
	});

	$('#divUniversity').html('');
	$('#divFaculty').html('');
	$('#divMajor').html('');
	ajaxJSonCheckBox("JsonCommonServlet3",'mode=university&'+parameter1+parameter2,divUniversity,universityName, "loadFaculty3('divFaculty','facultyName')");
}

function loadFaculty3(divFaculty,facultyName) {
	
	var parameter1 = '';
	var parameter2 = '';
	var parameter3 = '';
	
	$("#divZone :checked").each(function() {
		parameter1 = parameter1 + "zoneSelect="+toUnicode(this.value)+"&";
	});
	$("#divProvince :checked").each(function() {
		parameter2 = parameter2 + "provinceSelect="+toUnicode(this.value)+"&";
	});
	$("#divUniversity :checked").each(function() {
		parameter3 = parameter3 + "universitySelect="+toUnicode(this.value)+"&";
	});

	$('#divFaculty').html('');
	$('#divMajor').html('');
	ajaxJSonCheckBox("JsonCommonServlet3",'mode=faculty&'+parameter1+parameter2+parameter3,divFaculty,facultyName, "loadMajor3('divMajor','majorName')");
}

function loadMajor3(divMajor,majorName) {
	
	var parameter1 = '';
	var parameter2 = '';
	var parameter3 = '';
	var parameter4 = '';
	
	$("#divZone :checked").each(function() {
		parameter1 = parameter1 + "zoneSelect="+toUnicode(this.value)+"&";
	});
	$("#divProvince :checked").each(function() {
		parameter2 = parameter2 + "provinceSelect="+toUnicode(this.value)+"&";
	});
	$("#divUniversity :checked").each(function() {
		parameter3 = parameter3 + "universitySelect="+toUnicode(this.value)+"&";
	});
	$("#divFaculty :checked").each(function() {
		parameter4 = parameter4 + "facultySelect="+toUnicode(this.value)+"&";
	});

	$('#divMajor').html('');
	ajaxJSonCheckBox("JsonCommonServlet3",'mode=major&'+parameter1+parameter2+parameter3+parameter4,divMajor,majorName, "");
}

/////////////////////////////////////////////

function ajaxJSonCheckBox(urlServer, parameter,divNameCheckbox, checkboxName, functionName) {
	//alert(1);
	var oXHR = $.ajax({
   		url: urlServer,
   		data: parameter,
   		dataType :'json',
   		success: function(data) {
			//alert('resultJSon = '+data);
    		var container = $('#'+divNameCheckbox);
    		var inputs = container.find('input');
    		var id = inputs.length+1;
    		//alert(2);
	    	$.each(data, function(i, item) {
	    		//alert('item.valueCode = '+item.valueCode+" ,item.textName="+item.textName);
	    		$('<input />', { type: 'checkbox', id: 'cb'+i, value: item.valueCode, name: checkboxName, onclick: functionName }).appendTo(container);
	    		$('<label />', { 'for': 'cb'+i, text: item.textName }).appendTo(container);
	    		$('<BR>').appendTo(container);
	    		
			});
		},
		error : function(xhr, state, exception) {
			alert(exception);
			return null;
		}
	});
	    
}

function toUnicode(strValue) {
	var unicodeString = '';
	for (var i=0; i < strValue.length; i++) {
		var theUnicode = strValue.charCodeAt(i).toString(16).toUpperCase();
		while (theUnicode.length < 4) {
			theUnicode = '0' + theUnicode;
		}
		theUnicode = '\\u' + theUnicode;
		unicodeString += theUnicode;
	}
	
	return unicodeString;
}


